package com.cby.web.service;

import com.cby.web.bean.Student;
import com.cby.web.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class StudentServiceImpl implements StudentService{

    @Autowired
    StudentMapper studentMapper;

    @Override
    public Student getStudentById(int id) {
        System.out.println("id = "+id);
        if(studentMapper != null) {
            return studentMapper.getStudentById(id);
        }
        return null;
    }

    @Override
    public Student getStudentByName(String name) {
        try{
            System.out.println("name = "+name);
            if(studentMapper != null) {
                System.out.println("Start query database...");
                return studentMapper.getStudentByName(name);
            }
        }catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }
}
